////////////////////////////////////////////////////////////
/* MounterNPC Script Original written by Scarface//Odin  //
 *                                                      //
 * This script can be easily edited to be              //
 * used for your server. Throughout the script        //
 * are comments on what each thing does so that      //
 * you can edit this. You can create custom         //
 * teleporting locations and menus.                //
 *                                                //
 * Originally written for use with Moon++        //
 */                                             //
/////////////////////////////////////////////////


#include "StdAfx.h"
#include "Setup.h"

#ifdef WIN32
#pragma warning(disable:4305)        // warning C4305: 'argument' : truncation from 'double' to 'float'
#endif

#define MOUNTER_NPC 55558



class SCRIPT_DECL MounterNPC : public GossipScript{
  public:
    void GossipHello(Object * pObject, Player* Plr, bool AutoSend);
    void GossipSelectOption(Object * pObject, Player* Plr, uint32 Id, uint32 IntId, const char * Code);
    void GossipEnd(Object * pObject, Player* Plr){ GossipScript::GossipEnd(pObject, Plr); }
    void Destroy(){ delete this; }
};

void MounterNPC::GossipHello(Object* pObject, Player * Plr, bool AutoSend){
  if(Plr->CombatStatus.IsInCombat()){
    Plr->BroadcastMessage("You are in combat!");
  }else{
    GossipMenu *Menu;
    objmgr.CreateGossipMenuForPlayer(&Menu, pObject->GetGUID(), 2593, Plr);
    Menu->AddItem(0, "Mount Bat", 1);
    Menu->AddItem(0, "Mount Flying Bat (level 70)", 2);
    Menu->AddItem(0, "Dismount", 3);   
    if(AutoSend) Menu->SendTo(Plr);
  }
};

void MounterNPC::GossipSelectOption(Object* pObject, Player* Plr, uint32 Id, uint32 IntId, const char * Code){
  float  Speed     = 9.7;
  uint32 displayid = 0;
  uint32 eventid   = 5;
  bool   flytf     = false;
  switch(IntId){
    case 1:{ 
      if(Plr->getLevel() >= 60){
        flytf = true; eventid = 3; displayid = 1056; Speed = 25;
      }else {
        Plr->BroadcastMessage("You need to be atleast level 60 to ride this baby");  
      }
      break;
    }
    case 2:{ 
      if(Plr->getLevel() >= 70){
        flytf = true; eventid = 3; displayid = 1056; Speed = 30;
      }else {
        Plr->BroadcastMessage("You need to be atleast level 70 to ride this baby");  
      }
      break;
    }
  }
  WorldPacket pbuf(836, 13);
  Plr->m_setflycheat = flytf;
  pbuf << Plr->GetNewGUID();
  pbuf << uint32(eventid);
  Plr->SendMessageToSet(&pbuf, true);
  Plr->SetPlayerSpeed(RUN,     Speed);
  Plr->SetPlayerSpeed(SWIM,    Speed);
  Plr->SetPlayerSpeed(RUNBACK, Speed);
  Plr->SetPlayerSpeed(FLY,     Speed);
  Plr->SetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID, displayid);
}

void SetupMounterNPC(ScriptMgr *mgr){
  mgr->register_gossip_script(55558, (GossipScript*) new MounterNPC());
}
